-
Notifications
You must be signed in to change notification settings - Fork 1.1k
DATAMONGO-1835 - Add support for $jsonSchema to CollectionOptions and Criteria queries. #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… map and write schema to collection) We now can create a $jsonSchema that can be used as a validator when creating collections. Required fields and properties get mapped according to the @field annotation on domain objects. Currently the schema is written directly to the db. So there’s still a lot of work to do: * Increase test coverage * Add support for MongoJsonSchema as validator to CollectionOptions. * Run enum values through the conversion infrastructure. * Support reading back $jsonSchema from Database using the listCollections command. * Add support for usage of $jsonSchema in Criteria API * Update Javadoc & reference documentation.
…nSchema support to Criteria query.
Add JSON schema to collection creation using reactive API. Refactor MongoJsonSchema to interface with default implementations for JsonSchemaObject and Document-based schemas. Make fields final and methods static where possible. Add minItems/maxItems/additionalItems properties to ArrayJsonSchemaProperty. Add missing overrides to NullJsonSchemaProperty. Slightly rename methods for item/property counts. Add generics, Javadoc, minor tweaks.
mp911de
pushed a commit
that referenced
this pull request
Jan 12, 2018
We now can create a $jsonSchema that can be used as a validator when creating collections and as predicate for queries. Required fields and properties get mapped according to the @field annotation on domain objects. MongoJsonSchema schema = MongoJsonSchema.builder().required("firstname", "lastname") .properties(string("firstname").possibleValues("luke", "han"), object("address").properties(string("postCode").minLength(4).maxLength(5))) .build(); resulting in the following schema: { "type": "object", "required": [ "firstname", "lastname" ], "properties": { "firstname": { "type": "string", "enum": [ "luke", "han" ], }, "address": { "type": "object", "properties": { "postCode": { "type": "string", "minLength": 4, "maxLength": 5 } } } } } Query usage: MongoJsonSchema schema = MongoJsonSchema.builder() .required("address") .property(object("address").properties(string("street").matching("^Apple.*"))).build(); List<Person> person = template.find(query(matchingDocumentStructure(schema)), Person.class)); Collection validation: MongoJsonSchema schema = MongoJsonSchema.builder().required("firstname", "lastname") .properties(string("firstname").possibleValues("luke", "han"), object("address").properties(string("postCode").minLength(4).maxLength(5))) .build(); template.createCollection(Person.class, CollectionOptions.empty() .schema(schema) .failOnValidationError()); Original pull request: #524.
mp911de
added a commit
that referenced
this pull request
Jan 12, 2018
Add JSON schema to collection creation using reactive API. Refactor MongoJsonSchema to interface with default implementations for JsonSchemaObject and Document-based schemas. Make fields final and methods static where possible. Add minItems/maxItems/additionalItems properties to ArrayJsonSchemaProperty. Add missing overrides to NullJsonSchemaProperty. Slightly rename methods for item/property counts. Add generics, Javadoc, minor tweaks. Original pull request: #524.
That's now merged and polished. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We now support
$jsonSchema
for collection creation and withinCriteria
queries.Schema
properties
andrequiredProperties
are mapped against the domain types fields.enum
values use the conversion infrastructure to map values into the MongoDB specific representation.Related to #511 which should be added on top.